//
//  pauseLayer.m
//  pipi
//
//  Created by zhao ys on 5/14/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "pauseLayer.h"
#import "startupLayer.h"
#import "SoundManager.h"

@implementation pauseLayer

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	CCLayer *layer = [pauseLayer node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init])) {
		
		CCMenuItem * resume = [CCMenuItemFont itemFromString:@"[Resume]" target:self selector:@selector(OnResume)];
		CCMenuItem * restart = [CCMenuItemFont itemFromString:@"[Main Menu]" target:self selector:@selector(OnRestart)];
		
		
		//CCMenuItem * resume = [CCMenuItemImage itemFromNormalImage:@"pause.png" selectedImage:@"pause.png"
		//													 target:self selector:@selector(OnResume)];
		//CCMenuItem * restart = [CCMenuItemImage itemFromNormalImage:@"restart.png" selectedImage:@"restart.png"
		//												   target:self selector:@selector(OnRestart)];
		
		//CGSize pauseSize = pause.contentSize;
		//pause.position = ccp(size.width - pauseSize.width / 2, size.height - pauseSize.height / 2);
		CCMenu * menu = [CCMenu menuWithItems:resume, restart, nil];
		[menu alignItemsVertically];
		[self addChild:menu];
	}
	return self;
}

-(void) OnResume {
	[[CCDirector sharedDirector] popScene];
	[[SoundManager sharedManager] play:@"background" loops:-1];
	[[CCDirector sharedDirector] resume];
}

-(void) OnRestart {
	[[CCDirector sharedDirector] popScene];
	[[CCDirector sharedDirector] replaceScene:[startupLayer scene]];
	[[CCDirector sharedDirector] resume];
}

@end
